/**
 * @Author: Sagan
 * @Date: 2020/09/19 13:40
 */
package module

import (
	"gitee.com/big_meteor/godash/lang"
	"gitee.com/big_meteor/godash/validate/constant"
	"gitee.com/big_meteor/godash/validate/function"
	"reflect"
)

// 是否为有效的IP地址
// 支持的类型：string
func IP(v interface{}) (bool, error) {
	var rt reflect.Kind
	v, rt = lang.GetValue(v)

	if reflect.String != rt {
		return false, constant.ERROR_IP_UDT
	}
	return function.IP(v.(string)), nil
}

func IPv4(v interface{}) (bool, error) {
	var rt reflect.Kind
	v, rt = lang.GetValue(v)

	if reflect.String != rt {
		return false, constant.ERROR_IPV4_UDT
	}
	return function.IPv4(v.(string)), nil
}

func IPv6(v interface{}) (bool, error) {
	var rt reflect.Kind
	v, rt = lang.GetValue(v)

	if reflect.String != rt {
		return false, constant.ERROR_IPV6_UDT
	}
	return function.IPv6(v.(string)), nil
}
